   <?php
   error_reporting(E_ERROR | E_WARNING | E_PARSE);
   require_once 'dir.func.php';
   require_once 'file.func.php';
   require_once 'common.func.php';
   $path="file";
   $act=$_REQUEST['act'];
   $filename=$_REQUEST['filename'];
   $info=readDirectory($path);
   $redirect="index1.php?path={$path}";
   if($act=="createFile"){
       #echo $path,"--";
       #echo $filename;
       $mes=createFile($path."/".$filename);
       alertMes($mes,$redirect);
   }
   elseif($act=="showContent"){
       //查看文件内容
       $content=file_get_contents($filename);
       //echo "<textarea readonly='readonly' col='10' rows='10'>{$content}<textarea>";
       //echo "$content";
       if(strlen($content)){
        highlight_file($filename);
       }
       /*$newContent=highlight_string($content,true);
       $str=<<<EOF
       <table width='80%' bgcolor='#F0F0F0' cellpadding='5' cellspacing='0'>
          <tr>
             <td>
                  {$newContent}
             </td>
          </tr>
       </table>
       EOF;
       echo $str;*/
       else{
           alertMes("文件没有内容",$redirect);
       }
   }
   elseif($act=="editContent"){
       //echo "编辑文件";
       $content=file_get_contents($filename);
       //echo $filename;exit;
       $str=<<<EOF
          <form action='index1.php?act=doEdit' method='post'>
             <textarea name='content' cols='190' rows='10'>{$content}</textarea><br/>
             <input type='hidden' name='filename' value='{$filename}'/>
             <input type="submit" value="修改文件内容"/>
          </form>
EOF;
       echo $str;
   }
   elseif ($act=="doEdit"){
       $content=$_REQUEST['content'];
       //echo $filename;
       if(file_put_contents($filename,$content)){
           $mes="文件修改成功";
       }
       else{
           $mes="文件修改失败";
       }
       alertMes($mes,$redirect);
   }
   elseif($act=="renameFile"){
       //完成重命名
       $str=<<<EOF
       <form action="index1.php?act=doRename" method="post">
              请填写新文件名:<input type="text" name="newname" placeholder="重命名"/>
       <input type="hidden" name='filename' value='{$filename}'/>
       <input type="submit" value="重命名"/>
       </form>
EOF;
       echo $str;
   }
   elseif($act=="doRename"){
       //实现重命名操作
       $newname=$_REQUEST['newname'];
       $mes=renameFile($filename,$newname);
       alertMes($mes,$redirect);
   }
   elseif($act=="delFile"){
       //echo "文件删除了";
       $mes=delFile($filename);
       alertMes($mes,$redirect);
   }
   elseif($act=="downFile"){
       //完成下载的功能
       $mes=downFile($filename);
   }
?>

   <!DOCTYPE HTML>
   <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
   <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
   <title>Insert title here</title>
   <link rel="stylesheet" href="cikonss.css"/>
   <style type="text/css">
     body,p,div,ul,ol,table,dl,dd,dt{
	    margin:0;
     	padding:0;
     }
     a{
	    text-decoration:none;
     }
     ul,li{
	    list-style:none;
     	float:left;
     }
     #top{
	    width:100%;
     	height:48px;
     	margin:0 auto;
     	background:#E2E2E2;
     }
     #navi a{
	    display:block;
     	width:148px;
     	height:48px;
     }
     #main{
	    margin:0 auto;
     	border:2px solid #ABCDEF;
     }
     img{
	    width:25px;
     	height:25px;
     	border:0;
     }
   </style>
   <script type="text/javascript">
       function show(dis){
       document.getElementById(dis).style.display="block";
       }
       function delFile(filename){
          if(window.confirm("你确定要删除吗？删除后无法恢复哟")){
              location.href="index1.php?act=delFile&filename="+filename;
          }
       }
       function showDetail(t,filename){
            $("#showImg").attr("src",filename);
            $("#showDetail").dialog({
                height:"auto",
                width:"auto",
                position:{my:"center",at:"center",collision:"fit"},
                modal:false,//是否模式对话框
                draggable:true,//是否允许拖拽
                resizable:true,//是否允许拖动
                title:t,//对话框标题
                show:'slide',
                hide:'explode'
                });
           }
   </script>
   <head>

   <body>
   <div id="showDetail" style="display:none"><img src="" id="showImg" alt""/></div>
   <h1>慕课网-在线文件管理器</h1>
   <div id="top">
     <ul id="navi">
       <li><a href="index1.php" title="主目录">主目录</a></li>
       <li><a href="#" onclick="show('createFile')" title="新建文件">新建文件<span style="margin-left"></span></a></li>
       <li><a href="#" onclick="show('createFolder')" title="新建文件夹">新建文件夹</a></li>
       <li><a href="#" onclick="show('uploadFile')" title="上传文件">上传文件</a></li>
       <li><a href="#" title="返回上级目录" onclick="back('<?php ?>')">返回上级目录</a></li>
     </ul>
   </div>
   <form action="index1.php" method="post">
	<table width="100%" border="1" cellpadding="5" cellspacing="0"
		bgcolor="ABCDEF" algin="center">
		<tr id="createFolder" style="display: none;">
			<td>请输入文件夹名称</td>
			<td><input type="text" name="dirname" /> <input type="submit"
				name="act" value="创建文件夹" /></td>
		</tr>

		<tr id="createFile" style="display: none;">
			<td>请输入文件名称</td>
			<td><input type="text" name="filename" /> <input type="hidden"
				name="path" value="<?php echo $path;?>"> <input type="hidden"
				name="act" value="createFile" /> <input type="submit" value="创建文件" />
			</td>
		</tr>
		<tr id="uplodeFile" style="display: none;">
			<td>请选择要上传的文件</td>
			<td><input type="file" name="myfile" /> <input type="submit"
				name="act" value="上传文件" /></td>
		</tr>
		<tr>
			<td>编号</td>
			<td>名称</td>
			<td>类型</td>
			<td>大小</td>
			<td>可读</td>
			<td>可写</td>
			<td>可执行</td>
			<td>创建时间</td>
			<td>修改时间</td>
			<td>访问时间</td>
			<td>操作</td>
		</tr>
       <?php
    if($info['file']) {
        $i = 1;
        foreach ($info['file'] as $val) {
             ?>
           <tr>
			<td><?php echo $i;?></td>
			<td><?php echo $val;?></td>
			<td><?php echo filetype($path."/".$val);?></td>
			<td><?php echo transByte(filesize($path."/".$val));?></td>
			<td><?php if(is_readable($path."/".$val))echo "可读";else echo "不可读";?></td>
			<td><?php if(is_writeable($path."/".$val))echo "可写";else echo "不可写";?></td>
			<td><?php if(is_executable($path."/".$val))echo "可执行";else echo "不可执行";?></td>
			<td><?php echo date("Y-m-d h-i-s",filectime($path."/".$val))?></td>
			<td><?php echo date("Y-m-d h-i-s",filemtime($path."/".$val))?></td>
			<td><?php echo date("Y-m-d h-i-s",fileatime($path."/".$val))?></td>
			<?php
			//得到文件拓展名
			    $ext=strtolower(end(explode(".",$val)));
			    $imageExt=array("gif","jpg","jpeg","png");
			    if(in_array($ext,$imageExt)){
			       ?>
			        <a href="#" onclick="showDetail('<?php echo $val;?>','<?php echo $path."/".$val;?>')"></a>
			   <?php  }
			     else{?>
			       <a href="index1.php?act=showContent&filename=<?php echo $path."/".$val;?>"></a>
			    <?php }?>

			  <td><a href="index1.php?act=showContent&filename=<?php echo $path."/".$val;?>">查看</a>
			    <a href="index1.php?act=editContent&filename=<?php echo $path."/".$val;?>">修改</a>
			    <a href="index1.php?act=renameFile&filename=<?php echo $path."/".$val;?>">重命名</a>
			    <a href="#" onclick="delFile('<?php echo $path."/".$val;?>')">删除</a>
			     <a href="index1.php?act=downFile&filename=<?php echo $path."/".$val;?>">下载</a>
			    </td>
		</tr>
        <?php
            $i ++;
        }
    }
    ?>
</table>
</form>
</body>
</html>